package com.indusfo.spc.controller;

import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.pojo.Badpheno;
import com.indusfo.spc.pojo.BadphenoPro;
import com.indusfo.spc.service.BadphenoService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @ProjectName: IEIS2-COM
 * @Package: com.indusfo.spc.controller
 * @ClassName: BadphenoController
 * @Author: 熊冰
 * @Description: 不良现象 视图层
 * @Date: 2019/8/20 16:00
 * @Version: 1.0
 */

@Controller
@RequestMapping("/service/badpheno")
public class BadphenoController {
    /**
     * 注入service
     */
    @Resource
    BadphenoService badphenoService;

    //新增
    @RequestMapping(value = "insertBadpheno")
    @ResponseBody
    public JSONObject insertBadpheno(Badpheno badpheno) {
        badpheno.setBadphenoId(null);
        JSONObject json = badphenoService.insertOrUpdateBadpheno(badpheno);
        return json;
    }

    //删除
    @RequestMapping(value = "deleteBadpheno")
    @ResponseBody
    public JSONObject deleteBadpheno(Long[] ids) {
        JSONObject json = new JSONObject();
    	try {
    		Integer dataState = 2;
    		json = badphenoService.deleteBadpheno(ids, dataState);
    		return json;
		} catch (Exception e) {
			return json;
		}
    }

    //修改
    @RequestMapping(value = "updateBadpheno")
    @ResponseBody
    public JSONObject updateBadpheno(Badpheno badpheno) {
        JSONObject json = badphenoService.insertOrUpdateBadpheno(badpheno);
        return json;
    }

    //查询
    @RequestMapping(value = "queryBadpheno")
    @ResponseBody
    public JSONObject queryBadpheno(Badpheno badpheno) {
        JSONObject json = badphenoService.listBadpheno(badpheno);
        return json;
    }

    //启用/停用
    @RequestMapping(value = "definedBadpheno")
    @ResponseBody
    public JSONObject definedBadpheno(Long[] ids, Integer dataState) {
        JSONObject json = badphenoService.deleteBadpheno(ids, dataState);
        return json;
    }

    //添加不良原因关联
    @RequestMapping(value = "insertBadphenoBadcause")
    @ResponseBody
    public JSONObject insertBadphenoBadcause(Long[] ids, Integer badphenoId) {
        JSONObject json = badphenoService.insertBadphenoBadcause(ids, badphenoId);
        return json;
    }

    //删除不良原因关联
    @RequestMapping(value = "deleteBadphenoBadcause")
    @ResponseBody
    public JSONObject deleteBadphenoBadcause(Long[] ids, Integer badphenoId) {
        JSONObject json = badphenoService.deleteBadphenoBadcause(ids, badphenoId);
        return json;

    }

    //添加不良对策关联
    @RequestMapping(value = "insertBadphenoBadreply")
    @ResponseBody
    public JSONObject insertBadphenoBadreply(Long[] ids, Integer badphenoId) {
        JSONObject json = badphenoService.insertBadphenoBadreply(ids, badphenoId);
        return json;
    }

    //删除不良对策关联
    @RequestMapping(value = "deleteBadphenoBadreply")
    @ResponseBody
    public JSONObject deleteBadphenoBadreply(Long[] ids, Integer badphenoId) {
        JSONObject json = badphenoService.deleteBadphenoBadreply(ids, badphenoId);
        return json;
    }

    //查询不良原因
    @RequestMapping(value = "selectBadphenoBadcause")
    @ResponseBody
    public JSONObject selectBadphenoBadcause(Badpheno badpheno) {
        JSONObject json = badphenoService.selectBadphenoBadcause(badpheno);
        return json;
    }

    //查询不良对策
    @RequestMapping(value = "selectBadphenoBadreply")
    @ResponseBody
    public JSONObject selectBadphenoBadreply(Badpheno badpheno) {
        JSONObject json = badphenoService.selectBadphenoBadreply(badpheno);
        return json;
    }

    //全查不良对策
    @RequestMapping(value = "queryBadreply")
    @SystemControllerLog(description = "查询不良对策")
    @ResponseBody
    public JSONObject queryBadreply(Badpheno badpheno) {
        JSONObject json = badphenoService.queryBadreply(badpheno);
        return json;
    }

    //全查不良原因
    @RequestMapping(value = "queryBadcause")
    @SystemControllerLog(description = "查询不良原因")
    @ResponseBody
    public JSONObject queryBadcause(Badpheno badpheno) {
        JSONObject json = badphenoService.queryBadcause(badpheno);
        return json;
    }

    /**
     * @Date 2019/10/23 10:10
     * @Author wamgq
     * 查询不良工序
     */
    @RequestMapping(value = "queryPro")
    @ResponseBody
    public JSONObject queryPro(BadphenoPro badphenoPro) {
        JSONObject json = badphenoService.queryPro(badphenoPro);
        return json;
    }

    /**
     * @Date 2019/10/23 10:10
     * @Author wamgq
     * 新增不良工序
     */
    @RequestMapping(value = "insertPro")
    @ResponseBody
    public JSONObject insertPro(Long[] ids, Integer badphenoId) {
        JSONObject json = badphenoService.insertPro(ids, badphenoId);
        return json;
    }

    /**
     * @Date 2019/10/23 10:10
     * @Author wamgq
     * 删除不良工序
     */
    @RequestMapping(value = "delPro")
    @ResponseBody
    public JSONObject deletePro(Long[] ids, Integer badphenoId) {
        JSONObject json = badphenoService.deletePro(ids, badphenoId);
        return json;
    }

    /**
     * 去添加查询（产品，任务单，批次）
     */
    @RequestMapping(value = "/queryListBadphenoToInsert")
    @ResponseBody
    public JSONObject queryListBadphenoToInsert(Badpheno badpheno) {
        JSONObject json = badphenoService.queryListBadphenoToInsert(badpheno);
        return json;
    }
}
